package cn.edu.hzvtc.service.impl;

import cn.edu.hzvtc.dao.AreaMapper;
import cn.edu.hzvtc.pojo.Area;
import cn.edu.hzvtc.service.areaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("areaService")
public class areaServiceImpl implements areaService {
    @Autowired
    private AreaMapper areaMapper;

    @Override
    public int add(Area area) {
        return areaMapper.insert(area);
    }

    public int update(Area area) {
        Area areaUpdate=areaMapper.selectByPrimaryKey(area.getId());
        areaUpdate.setAreaName(area.getAreaName());
        areaUpdate.setAreaSortNum(area.getAreaSortNum());
        return areaMapper.updateByPrimaryKey(areaUpdate);
    }

    public int delete(int id){
        Integer result=null;
        if (areaMapper.selectByPrimaryKey(id)==null){
            result=-1;
        }else {
            result= areaMapper.delStateByPrimaryKey(id);
        }
        return result;
    }


    @Override
    public List<Area> getTree(int parentId){
        return areaMapper.selectAllForTree(parentId);
    }

    @Override
    public List<Area> getChildren(Integer parentId) {
        return areaMapper.selectByParentId(parentId);
    }

    public Long getCount(Integer areaType) {
        return areaMapper.getCount(areaType);
    }
}

